﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BookStore.Bussiness;
using BookStore.Data;


namespace BookStore.Controls
{
    public partial class ProductList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
        {
            LoadData();
        }
        }
        public void LoadData()
        {
            listproduct.DataSource = Bussiness.productService.Top_productOLD();
            listproduct.DataBind();
        }
        public string FormatPrice(string values) 
        {
            values = values.Replace(",","");
            values = values.Replace(".", "");
            string s = "";
            while (values.Length > 3)
            {
                s = "." + values.Substring(values.Length - 3) + s;
                values = values.Substring(0,values.Length-3);
            }
            s = values + s + " usd";
            return s;
        }

        protected void lnbname_Click(object sender, EventArgs e)
        {
            LinkButton lnb = (LinkButton)sender;
            string id = lnb.CommandArgument;
            Response.Redirect("ProductDetail.aspx?productId=" + id);
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            LinkButton lnb = (LinkButton)sender;
            int id = Convert.ToInt32(lnb.CommandArgument);
            productService biz = new productService();
            productInfo sp = biz.getById(id);

            Cart objCart = new Cart();
            if (Session["cart"] != null)
                objCart = (Cart)Session["cart"];
            objCart.AddToCart(sp);
            Session["cart"] = objCart;
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            LinkButton lnb = (LinkButton)sender;
            int id = Convert.ToInt32(lnb.CommandArgument);
            productService biz = new productService();
            productInfo sp = biz.getById(id);

            Cart objCart = new Cart();
            if (Session["cart"] != null)
                objCart = (Cart)Session["cart"];
            objCart.AddToCart(sp);
            Session["cart"] = objCart;
        
        }
        protected void lbnimg_Click(object sender, EventArgs e)
        {
            LinkButton lnb = (LinkButton)sender;
            string id = lnb.CommandArgument;
            Response.Redirect("Productdetail.aspx?productId=" + id);
        }
    }
}